package com.lanchetech.admin.controller;

import com.lanchetech.admin.service.OrderService;
import com.lanchetech.admin.service.UserService;
import com.lanchetech.bean.request.CountByTimeReq;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.BigDecimalCountByDateVO;
import com.lanchetech.bean.vo.LongCountByDateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "图表数据查询", tags = "图表数据查询")
@RequestMapping("/api/data")
@RestController
public class DataController {

    @Autowired
    UserService userService;

    @Autowired
    OrderService orderService;


    @ApiOperation(value = "获取一个时间段内最多30天的用户注册数量统计")
    @PostMapping("/getRegisterUserCount")
//    @PreAuthorize("hasAuthority('data_customer_page')")
    public ResultData<List<LongCountByDateVO>> getRegisterUserCount(@RequestBody CountByTimeReq req) {
        return userService.getRegisterUserCount(req);
    }


    @ApiOperation(value = "统计指定时间区间的日订单数量（订单状态为已支付、待评论、已完成）")
    @PostMapping("/getOrdersCount")
//    @PreAuthorize("hasAuthority('data_customer_page')")
    public ResultData<List<LongCountByDateVO>> getOrdersCount(@RequestBody CountByTimeReq req) {
        return orderService.getOrdersCount(req);
    }

    @ApiOperation(value = "统计指定时间区间的日销售金额（订单状态为已支付、待评论、已完成）")
    @PostMapping("/getPayAmountCount")
//    @PreAuthorize("hasAuthority('data_customer_page')")
    public ResultData<List<BigDecimalCountByDateVO>> getPayAmountCount(@RequestBody CountByTimeReq req) {
        return orderService.getPayAmountCount(req);
    }


}
